from fastapi import APIRouter, Depends

from db.models.wx_friends import FriendTagRequest, MessageParams, TagRequest
from services.wx_friends_service import get_friends_by_nickname, set_friends_tag, remove_friends_tag, \
    add_tag, remove_tag, get_tags, get_fd_by_wx_id, get_rag_detail

from db.models.wx_friends import FriendTagRequest, FriendRemarkRequest
from services.wx_friends_service import get_friends_by_nickname, set_friends_tag, remove_friends_tag, get_friend_detail, \
    set_friends_remark, get_friends_with_chat_history
from utils.result import Result

router = APIRouter()

@router.get("/wx_friends")
async def wx_friends(device_id: str ,nickname: str = None,tag: str = None):
    return await get_friends_by_nickname(device_id, nickname, tag)

@router.post("/wx_friends/tags")
async def wx_friends(req: FriendTagRequest):
    return await set_friends_tag(req.device_id, req.wx_ids,req.tag)


@router.post("/wx_friends/remove/tags")
async def wx_friends(req: FriendTagRequest):
    return await remove_friends_tag(req.device_id, req.wx_ids,req.tag)

@router.post("/add/tag")
async def wx_message(req: TagRequest):
    return await add_tag(req.tag)
@router.post("/del/tag")
async def wx_message(req: TagRequest):
    return await remove_tag(req.tag)

@router.get("/tags")
async def wx_message():
    return await get_tags()


@router.get("/wx_friends/detail")
async def wx_friends(key: str,wx_id: str,device_id: str):
    if device_id.startswith("rag"):
        fr = await get_rag_detail(wx_id,device_id)
        return Result.success(fr)
    return await get_friend_detail(key,wx_id,device_id)

@router.post("/wx_friends/remark")
async def wx_friends(request: FriendRemarkRequest):
    return await set_friends_remark(request.device_id, request.wx_id, request.remark)

@router.get("/wx_friends/history")
async def wx_friends(device_id: str):
    return await get_friends_with_chat_history(device_id)